package com.bootdo.appsystem.service.impl;

import com.bootdo.app.htmlVO.index.SellerAndGoods;
import com.bootdo.app.utils.redis.AppRedisUtil;
import com.bootdo.appsystem.dao.SellerDao;
import com.bootdo.appsystem.domain.SellerDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.appsystem.dao.ProducesinfoDao;
import com.bootdo.appsystem.domain.ProducesinfoDO;
import com.bootdo.appsystem.service.ProducesinfoService;



@Service
public class ProducesinfoServiceImpl implements ProducesinfoService {
	@Autowired
	private ProducesinfoDao producesinfoDao;
	@Autowired
	private SellerDao sellerDao;
	
	@Override
	public ProducesinfoDO get(Integer pid){
		return producesinfoDao.get(pid);
	}
	
	@Override
	public List<ProducesinfoDO> list(Map<String, Object> map){
		return producesinfoDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return producesinfoDao.count(map);
	}
	
	@Override
	public int save(ProducesinfoDO producesinfo){
		return producesinfoDao.save(producesinfo);
	}
	
	@Override
	public int update(ProducesinfoDO producesinfo){
		return producesinfoDao.update(producesinfo);
	}
	
	@Override
	public int remove(Integer pid){
		return producesinfoDao.remove(pid);
	}
	
	@Override
	public int batchRemove(Integer[] pids){
		return producesinfoDao.batchRemove(pids);
	}

	@Override
	public List<ProducesinfoDO> getIndexList() {
		List<ProducesinfoDO> indexProducesinfoList = null;
		indexProducesinfoList = AppRedisUtil.get("indexProducesinfoList");
		if (indexProducesinfoList == null) {
			HashMap<String, Object> map = new HashMap<>();
			map.put("isbest" , 1);
			map.put("sort" , "IsHot");
			map.put("order" , "ASC");
			indexProducesinfoList = this.list(map);
			AppRedisUtil.put("indexProducesinfoList",indexProducesinfoList);
		}
		return indexProducesinfoList;
	}

	@Override
	public List<SellerAndGoods> getTJGoodsAll() {
        List<SellerAndGoods> getTJGoodsAll = AppRedisUtil.get("getTJGoodsAll");
		if(getTJGoodsAll == null){
			getTJGoodsAll = new ArrayList<SellerAndGoods>();
			//查询所有有推荐商品的商家
			List<SellerDO> sellerDOList = sellerDao.listGoodsTJ();
			for (SellerDO sellerDO : sellerDOList) {
				SellerAndGoods sellerAndGoods = new SellerAndGoods();
				sellerAndGoods.setSellerDO(sellerDO);
				HashMap<String, Object> map = new HashMap<>();
				map.put("mediumcount" , 1);
				map.put("isnew" , 1);
				map.put("isfree" , 1);
				map.put("sellerid" , sellerDO.getSellerid());
				map.put("sort" , "IsHot");
				map.put("order" , "ASC");
				List<ProducesinfoDO> list = this.list(map);
				sellerAndGoods.setProducesinfoList(list);
				getTJGoodsAll.add(sellerAndGoods);
			}
			AppRedisUtil.put("getTJGoodsAll",getTJGoodsAll);
		}
		return getTJGoodsAll;
	}

}
